home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / lib / python2.6 / dist-packages / softwareproperties / gtk / DialogAddSourcesList.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2009-04-20  |  5.0 KB  |  125 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. import pygtk
  5. import gtk
  6. import gtk.glade as gtk
  7. import gobject
  8. import os
  9. from optparse import OptionParser
  10. from gettext import gettext as _
  11. import gettext
  12. import urllib
  13. from aptsources.sourceslist import SourcesList, SourceEntryMatcher
  14.  
  15. class DialogAddSourcesList:
  16.     
  17.     def __init__(self, parent, sourceslist, source_renderer, get_comparable, datadir, file):
  18.         print file
  19.         self.parent = parent
  20.         self.source_renderer = source_renderer
  21.         self.sourceslist = sourceslist
  22.         self.get_comparable = get_comparable
  23.         self.file = self.format_uri(file)
  24.         self.glade = gtk.glade.XML(os.path.join(datadir, 'glade/dialogs.glade'))
  25.         self.glade.signal_autoconnect(self)
  26.         self.dialog = self.glade.get_widget('dialog_add_sources_list')
  27.         self.label = self.glade.get_widget('label_sources')
  28.         self.button_add = self.glade.get_widget('button_add')
  29.         self.button_cancel = self.glade.get_widget('button_cancel')
  30.         self.button_replace = self.glade.get_widget('button_replace')
  31.         self.treeview = self.glade.get_widget('treeview_sources')
  32.         self.scrolled = self.glade.get_widget('scrolled_window')
  33.         self.image = self.glade.get_widget('image_sources_list')
  34.         self.dialog.realize()
  35.         if self.parent != None:
  36.             self.dialog.set_transient_for(parent)
  37.         else:
  38.             self.dialog.set_title(_('Add Software Channels'))
  39.         self.dialog.window.set_functions(gtk.gdk.FUNC_MOVE)
  40.         self.store = gtk.ListStore(gobject.TYPE_STRING)
  41.         self.treeview.set_model(self.store)
  42.         cell = gtk.CellRendererText()
  43.         cell.set_property('xpad', 2)
  44.         cell.set_property('ypad', 2)
  45.         column = gtk.TreeViewColumn('Software Channel', cell, markup = 0)
  46.         column.set_max_width(500)
  47.         self.treeview.append_column(column)
  48.         
  49.         try:
  50.             self.new_sources = SingleSourcesList(self.file)
  51.         except:
  52.             self.error()
  53.             return None
  54.  
  55.         if len(self.new_sources.list) > 0:
  56.             counter = 0
  57.             for source in self.new_sources.list:
  58.                 if source.invalid or source.disabled:
  59.                     continue
  60.                 
  61.                 self.new_sources.matcher.match(source)
  62.             
  63.             self.new_sources.list.sort(key = self.get_comparable)
  64.             for source in self.new_sources.list:
  65.                 if source.invalid or source.disabled:
  66.                     continue
  67.                 
  68.                 counter = counter + 1
  69.                 line = self.source_renderer(source)
  70.                 self.store.append([
  71.                     line])
  72.             
  73.             if counter == 0:
  74.                 self.error()
  75.                 return None
  76.             header = gettext.ngettext('Install software additionally or only from this source?', 'Install software additionally or only from these sources?', counter)
  77.             body = _('You can either add the following sources or replace your current sources by them. Only install software from trusted sources.')
  78.             self.label.set_markup('<big><b>%s</b></big>\n\n%s' % (header, body))
  79.         else:
  80.             self.error()
  81.             return None
  82.         return counter == 0
  83.  
  84.     
  85.     def error(self):
  86.         self.button_add.hide()
  87.         self.button_cancel.set_use_stock(True)
  88.         self.button_cancel.set_label('gtk-close')
  89.         self.button_replace.hide()
  90.         self.scrolled.hide()
  91.         self.image.set_from_stock(gtk.STOCK_DIALOG_ERROR, gtk.ICON_SIZE_DIALOG)
  92.         header = _('There are no sources to install software from')
  93.         body = _("The file '%s' does not contain any valid software sources." % self.file)
  94.         self.label.set_markup('<big><b>%s</b></big>\n\n%s' % (header, body))
  95.  
  96.     
  97.     def run(self):
  98.         res = self.dialog.run()
  99.         self.dialog.destroy()
  100.         return (res, self.new_sources)
  101.  
  102.     
  103.     def format_uri(self, uri):
  104.         path = urllib.url2pathname(uri)
  105.         path = path.strip('\r\n\x00')
  106.         if path.startswith('file:\\\\\\'):
  107.             path = path[8:]
  108.         elif path.startswith('file://'):
  109.             path = path[7:]
  110.         elif path.startswith('file:'):
  111.             path = path[5:]
  112.         
  113.         return path
  114.  
  115.  
  116.  
  117. class SingleSourcesList(SourcesList):
  118.     
  119.     def __init__(self, file):
  120.         self.matcher = SourceEntryMatcher('/usr/share/update-manager/channels/')
  121.         self.list = []
  122.         self.load(file)
  123.  
  124.  
  125.